package lxj;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class User2 {
    private int score;

    private int age;

    public User2(int score, int age){
        super();
        this.score = score;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User2{" +
                "score=" + score +
                ", age=" + age +
                '}';
    }


    public static void main(String[] args) {
        List<User> users = new ArrayList<User>();
        users.add(new User(78, 26));
        users.add(new User(67, 23));
        users.add(new User(34, 56));
        users.add(new User(55, 23));

        //按自己想法排序
        Collections.sort(users, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                int i= o2.getAge()-o1.getAge();   //年龄降序
                if(i==0){
                    return o1.getScore()-o2.getScore();  //年龄相同,按分数升序
                }
                return i;
            }
        });
        for(User user : users){
            System.out.println(user.getScore() + "," + user.getAge());
        }
    }
}
